<template>
  <div class="login-container">
    <div class="cyber-background">
      <div class="grid"></div>
      <div class="circles">
        <div class="circle"></div>
        <div class="circle"></div>
        <div class="circle"></div>
      </div>
    </div>
    
    <div class="login-card">
      <div class="card-header">
        <div class="cyber-line"></div>
        <h2>系统登录</h2>
        <p class="subtitle">MANAGEMENT SYSTEM</p>
      </div>
      
      <el-form 
        :model="loginForm" 
        :rules="rules" 
        ref="loginFormRef"
        class="login-form"
      >
        <el-form-item prop="username">
          <el-input 
            v-model="loginForm.username" 
            placeholder="用户名"
            :prefix-icon="User"
            class="cyber-input"
          />
        </el-form-item>
        
        <el-form-item prop="password">
          <el-input 
            v-model="loginForm.password" 
            type="password" 
            placeholder="密码"
            :prefix-icon="Lock"
            show-password
            class="cyber-input"
          />
        </el-form-item>
        
        <div class="form-footer">
          <el-checkbox v-model="rememberMe">记住我</el-checkbox>
          <a href="#" class="forgot-password">忘记密码？</a>
        </div>
        
        <el-button 
          type="primary" 
          class="submit-btn"
          :loading="loading"
          @click="handleLogin"
        >
          登 录
          <div class="btn-glitch"></div>
        </el-button>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { User, Lock } from '@element-plus/icons-vue'

const router = useRouter()
const loginFormRef = ref(null)
const loading = ref(false)
const rememberMe = ref(false)

const loginForm = reactive({
  username: '',
  password: ''
})

const rules = {
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
}

const handleLogin = async () => {
  if (!loginFormRef.value) return
  
  await loginFormRef.value.validate(async (valid) => {
    if (valid) {
      loading.value = true
      try {
        // TODO: 调用登录API
        router.push('/')
      } catch (error) {
        ElMessage.error('登录失败')
      } finally {
        loading.value = false
      }
    }
  })
}
</script>

<style scoped lang="scss">
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  position: relative;
  overflow: hidden;

  .cyber-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    
    .grid {
      position: absolute;
      width: 200%;
      height: 200%;
      background-image: 
        linear-gradient(transparent 95%, rgba(0, 255, 255, 0.3) 95%),
        linear-gradient(90deg, transparent 95%, rgba(0, 255, 255, 0.3) 95%);
      background-size: 40px 40px;
      animation: grid 20s linear infinite;
      transform: perspective(500px) rotateX(45deg);
      transform-origin: 50% 0;
    }

    .circles {
      position: absolute;
      width: 100%;
      height: 100%;
      
      .circle {
        position: absolute;
        border: 2px solid rgba(0, 255, 255, 0.2);
        border-radius: 50%;
        animation: pulse 4s ease-out infinite;
        
        &:nth-child(1) {
          width: 600px;
          height: 600px;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          animation-delay: -1s;
        }
        
        &:nth-child(2) {
          width: 400px;
          height: 400px;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          animation-delay: -2s;
        }
        
        &:nth-child(3) {
          width: 200px;
          height: 200px;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          animation-delay: -3s;
        }
      }
    }
  }

  .login-card {
    width: 400px;
    padding: 40px;
    background: rgba(20, 20, 20, 0.9);
    border: 1px solid rgba(0, 255, 255, 0.2);
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.1);
    z-index: 2;
    position: relative;
    overflow: hidden;
    
    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: -100%;
      width: 100%;
      height: 2px;
      background: linear-gradient(90deg, transparent, #0ff);
      animation: scan 3s linear infinite;
    }

    .card-header {
      text-align: center;
      margin-bottom: 30px;
      position: relative;
      
      .cyber-line {
        width: 100px;
        height: 2px;
        background: #0ff;
        margin: 0 auto 20px;
        position: relative;
        
        &::before,
        &::after {
          content: '';
          position: absolute;
          width: 10px;
          height: 10px;
          background: #0ff;
          top: -4px;
        }
        
        &::before {
          left: 0;
        }
        
        &::after {
          right: 0;
        }
      }

      h2 {
        color: #fff;
        font-size: 28px;
        font-weight: 600;
        margin-bottom: 5px;
        text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
      }
      
      .subtitle {
        color: #0ff;
        font-size: 14px;
        letter-spacing: 3px;
        opacity: 0.8;
      }
    }

    .login-form {
      :deep(.cyber-input) {
        .el-input__wrapper {
          background: rgba(0, 255, 255, 0.05);
          border: 1px solid rgba(0, 255, 255, 0.2);
          box-shadow: none;
          
          &.is-focus {
            border-color: #0ff;
            box-shadow: 0 0 10px rgba(0, 255, 255, 0.2);
          }
          
          .el-input__inner {
            color: #fff;
            
            &::placeholder {
              color: rgba(255, 255, 255, 0.4);
            }
          }
          
          .el-input__prefix-icon {
            color: #0ff;
          }
        }
      }

      .form-footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
        
        :deep(.el-checkbox) {
          .el-checkbox__label {
            color: rgba(255, 255, 255, 0.8);
          }
          
          .el-checkbox__input.is-checked .el-checkbox__inner {
            background-color: #0ff;
            border-color: #0ff;
          }
        }
        
        .forgot-password {
          color: rgba(0, 255, 255, 0.8);
          text-decoration: none;
          font-size: 14px;
          
          &:hover {
            color: #0ff;
            text-shadow: 0 0 5px #0ff;
          }
        }
      }

      .submit-btn {
        width: 100%;
        height: 44px;
        background: rgba(0, 255, 255, 0.1);
        border: 1px solid #0ff;
        font-size: 16px;
        font-weight: 500;
        color: #0ff;
        position: relative;
        overflow: hidden;
        
        &:hover {
          background: rgba(0, 255, 255, 0.2);
          box-shadow: 0 0 20px rgba(0, 255, 255, 0.2);
          
          .btn-glitch {
            opacity: 1;
          }
        }
        
        .btn-glitch {
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.2), transparent);
          opacity: 0;
          animation: glitch 1.5s linear infinite;
        }
      }
    }
  }
}

@keyframes grid {
  0% {
    transform: perspective(500px) rotateX(45deg) translateY(0);
  }
  100% {
    transform: perspective(500px) rotateX(45deg) translateY(-40px);
  }
}

@keyframes pulse {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.8;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.5);
    opacity: 0;
  }
}

@keyframes scan {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

@keyframes glitch {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}
</style> 